package sword;

/**
 * @Author: 海琳琦
 * @Date: 2022/5/31 11:23
 * https://leetcode.cn/problems/shu-de-zi-jie-gou-lcof/
 */
public class Title26 {

    class TreeNode{
        int val;

        TreeNode left;

        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }


    public boolean isSubStructure(TreeNode a, TreeNode b) {
        if (a == null || b == null) {
            return false;
        }
        //判断当前节点的根节点是否包含b，若不包含，前序递归
        return dfs(a, b) || isSubStructure(a.left, b) || isSubStructure(a.right, b);
    }

    private boolean dfs(TreeNode a, TreeNode b) {
        if (b == null) {
            return true;
        }
        if (a == null) {
            return false;
        }
        return a.val == b.val && dfs(a.left, b.left) && dfs(a.right, b.right);
    }


    public static void main(String[] args) {

    }
}
